var Q  = require("q")

//批处理函数的返回结果
var defer1 = Q.defer();
var defer2 = Q.defer();

var method1 = function(err, result1){
    if(err){
        return defer1.reject(err);
    }

    defer1.resolve(result1);
}

var method2 = function(err, result2){
    if(err){
        defer2.reject(err);
    }

    defer2.resolve(result2);
}

method1(null, "huang");
method2(null, "shangbin");

Q.all([defer1.promise, defer2.promise]).catch(function(err){
    console.log("某一个函数有误");
}).done(function(results){
    var result1 = results[0];
    var result2 = results[1];

    console.log(result1);
    console.log(result2);
});










































